package com.rw.daoImpl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.rw.dao.OrderItemDao;
import com.rw.table.Orderitem;

public class OrderItemDaoImpl extends HibernateDaoSupport implements OrderItemDao {

	@Override
	public Orderitem get(Long id) {

		return this.getHibernateTemplate().get(Orderitem.class, id);
	}

	@Override
	public boolean delete(Long id) {

		try {
			this.getHibernateTemplate().delete(this.get(id));
			return true;
		} catch (Exception e) {

			return false;
		}
	}

	@Override
	public boolean update(Orderitem orderitem) {

		try {
			this.getHibernateTemplate().update(orderitem);
			return true;
		} catch (Exception e) {

			return false;
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Orderitem> findOrderItemByItemId(Long id) {

		return this.getHibernateTemplate().find("select oi from Orderitem oi where oi.orderItemId = " + "'" + id +"'");
	}


	
	@SuppressWarnings("unchecked")
	@Override
	public List<Orderitem>   findOrderItemByOrderId(Long orderId) {

		
	     return	  this.getHibernateTemplate().find("select u from Orderitem u where u.orderId = ?", orderId);
		
	}
}
